package org.jeecg.codegeneweb.mock;

import lombok.Data;
import org.jeecg.codegeneweb.domian.column.*;
import org.jeecg.codegeneweb.enumtype.EnumModelType;
import org.jeecg.codegeneweb.vo.TableVoDomain;
import org.jeecg.codegeneweb.vo.WebModelVo;

import java.util.UUID;

@Data
public class TreeMockWebModelVo {
    public static WebModelVo initWo() throws Exception{
        WebModelVo wm = initWebModel();
        setWebModelWithTree(wm);
        return wm;
    }
    private static WebModelVo initWebModel() throws Exception {
        WebModelVo wm=new WebModelVo();
        wm = WebModelVo.builder()
                .codefromClientGUID(UUID.randomUUID().toString())
                .destinationOutPutDir("D:\\\\eclipse2018-workspace\\\\jeecg-boot\\\\singletable")
                .servicename("service")
                .jformType("1")
                .packageName("testshoptypetree")
                .modeltype(EnumModelType.TREE)
                .build();
        return wm;
    }
    private static void setWebModelWithTree(WebModelVo wm) {


        TableVoDomain singletree = new TableVoDomain();
        singletree.setScroll(1);
        singletree.setFormTemplate("1");
        singletree.setEntityName("TestShoptypeTree");
        singletree.setTableName("test_shoptype_tree");
        singletree.setTableTxt("商品分类");
        //下面是树的设置
        singletree.setIsTree("Y");//如果不是树，为N
        singletree.setTreeFieldname("type_name");////如果不是树，为null
        singletree.setTreeIdField("has_child");//如果不是树，为null
        singletree.setTreeParentIdField("pid");//如果不是树，为null
        //((SingleTableDomain)singletree).setTreeParentIdField("pid");//如果不是树，为null

        setpkid(singletree,1);
        setcreateby(singletree,2);
        setCreatTime(singletree, 3);
        setUpdateBy(singletree, 4);
        setUpdatetime(singletree, 5);
        setupSysorgCode(singletree,6);
        //业务字段
        setupTypeName(singletree,7);
        setupImage(singletree,8);
        setupParent(singletree,9);
        setupHasChild(singletree,10);

        wm.setTableVoDomain(singletree);


    }









    private static void setupSysorgCode(TableVoDomain singletable, int orderNum) {
        //设置id
        DbVo dbVosysorgcode = DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("sys_org_code")
                .dbFieldTxt("所属部门")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .dbLength(120)
                .build();
        PageVo pageVosysorgcode = PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(orderNum)
                .build();
        ValidateVo validateVosysorgcode = ValidateVo.builder()
                .fieldHref("")

                .build();
        ForeignKeyVo foreignKeyVosysorgcode = ForeignKeyVo.builder()
                .build();
        IndexVo indexVosysorgcode = IndexVo.builder()
                .build();
        SearchVo searchVosysorgcode = SearchVo.builder()
                .build();

        ColumnVoDomain columnId = ColumnVoDomain.builder()
                .dbVo(dbVosysorgcode)
                .pageVo(pageVosysorgcode)
                .validateVo(validateVosysorgcode)
                .foreignKeyVo(foreignKeyVosysorgcode)
                .indexVo(indexVosysorgcode)
                .searchVo(searchVosysorgcode)
                .build();

        singletable.getColumnVoDomainList().add(columnId);
    }

    private static void setpkid(TableVoDomain singletable, int orderNum) {
        //设置id
        DbVo dbVoid = DbVo.builder()
                .dbIsKey(1)
                .dbFieldName("id")
                .dbFieldTxt("主键")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(0)
                .dbLength(120)
                .build();
        PageVo pageVoid = PageVo.builder()
                .isShowForm(0)
                .isReadOnly(1)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(1)
                .build();
        ValidateVo validateVoid = ValidateVo.builder()
                .fieldHref("")
                //.dictField("")
                //.dictTable("")
                //.dictText("")
                .build();
        ForeignKeyVo foreignKeyVo = ForeignKeyVo.builder()
                .build();
        IndexVo indexVo = IndexVo.builder()
                .build();
        SearchVo searchVo = SearchVo.builder()
                .build();

        ColumnVoDomain columnId = ColumnVoDomain.builder()
                .dbVo(dbVoid)
                .pageVo(pageVoid)
                .validateVo(validateVoid)
                .foreignKeyVo(foreignKeyVo)
                .indexVo(indexVo)
                .searchVo(searchVo)
                .build();

        singletable.getColumnVoDomainList().add(columnId);
    }
    private static void setcreateby(TableVoDomain singletable, int orderNum) {
        //设置create_by
        DbVo dbcreateby= DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("create_by")
                .dbFieldTxt("创建人")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .dbLength(120)
                .build();
        PageVo pageVocreateby=PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(2)
                .build();
        ValidateVo validatecreateby=ValidateVo.builder()
                .fieldHref("")

                .build();
        ForeignKeyVo foreignKeyVocreateby=ForeignKeyVo.builder()
                .build();
        IndexVo indexVocreateby=IndexVo.builder()
                .build();
        SearchVo searchVocreateby=SearchVo.builder()
                .build();

        ColumnVoDomain columncreateby = ColumnVoDomain.builder()
                .dbVo(dbcreateby)
                .pageVo(pageVocreateby)
                .validateVo(validatecreateby)
                .foreignKeyVo(foreignKeyVocreateby)
                .indexVo(indexVocreateby)
                .searchVo(searchVocreateby)
                .build();
        singletable.getColumnVoDomainList().add(columncreateby);


    }

    private static void setUpdatetime(TableVoDomain singletable, int orderNum) {
        //设置upTime
        DbVo dbupTime=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("update_time")
                .dbFieldTxt("更新日期")
                .dbType("Date")
                .dbLength(120)
                .dbIsNull(1)
                .dbLength(120)
                .build();
        PageVo pageVoupTime=PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("datetime")
                .orderNum(orderNum)
                .build();
        ValidateVo validateupTime=ValidateVo.builder()
                .fieldHref("")

                .build();
        ForeignKeyVo foreignKeyVoupTime=ForeignKeyVo.builder()
                .build();
        IndexVo indexVoupTime=IndexVo.builder()
                .build();
        SearchVo searchVoupTime=SearchVo.builder()
                .build();

        ColumnVoDomain columnupTime = ColumnVoDomain.builder()
                .dbVo(dbupTime)
                .pageVo(pageVoupTime)
                .validateVo(validateupTime)
                .foreignKeyVo(foreignKeyVoupTime)
                .indexVo(indexVoupTime)
                .searchVo(searchVoupTime)
                .build();
        singletable.getColumnVoDomainList().add(columnupTime);
    }

    private static void setUpdateBy(TableVoDomain singletable, int orderNum) {
        //设置create_Time
        DbVo dbUpdateBy=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("update_by")
                .dbFieldTxt("更新人")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .build();
        PageVo pageVoUpdateBy=PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(orderNum)
                .build();
        ValidateVo validateUpdateBy=ValidateVo.builder()
                .fieldHref("")

                .build();
        ForeignKeyVo foreignKeyVoUpdateBy=ForeignKeyVo.builder()
                .build();
        IndexVo indexVoUpdateBy=IndexVo.builder()
                .build();
        SearchVo searchVoUpdateBy=SearchVo.builder()
                .build();

        ColumnVoDomain columnUpdateBy = ColumnVoDomain.builder()
                .dbVo(dbUpdateBy)
                .pageVo(pageVoUpdateBy)
                .validateVo(validateUpdateBy)
                .foreignKeyVo(foreignKeyVoUpdateBy)
                .indexVo(indexVoUpdateBy)
                .searchVo(searchVoUpdateBy)
                .build();
        singletable.getColumnVoDomainList().add(columnUpdateBy);
    }

    private static void setCreatTime(TableVoDomain singletable,Integer orderNum) {
        //设置create_Time
        DbVo dbcreateTime=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("create_time")
                .dbFieldTxt("创建日期")
                .dbType("Date")
                .dbLength(120)
                .dbIsNull(1)
                .dbLength(120)
                .build();
        PageVo pageVocreateTime=PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("datetime")
                .orderNum(orderNum)
                .build();
        ValidateVo validatecreateTime=ValidateVo.builder()
                .fieldHref("")

                .build();
        ForeignKeyVo foreignKeyVocreateTime=ForeignKeyVo.builder()
                .build();
        IndexVo indexVocreateTime=IndexVo.builder()
                .build();
        SearchVo searchVocreateTime=SearchVo.builder()
                .build();

        ColumnVoDomain columncreateTime = ColumnVoDomain.builder()
                .dbVo(dbcreateTime)
                .pageVo(pageVocreateTime)
                .validateVo(validatecreateTime)
                .foreignKeyVo(foreignKeyVocreateTime)
                .indexVo(indexVocreateTime)
                .searchVo(searchVocreateTime)
                .build();
        singletable.getColumnVoDomainList().add(columncreateTime);
    }

    private static void setupTypeName(TableVoDomain singletree, int orderNum) {

        //设置dbTypeName
        DbVo dbVo=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("type_name")
                .dbFieldTxt("商品分类")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .build();
        PageVo pageVo=PageVo.builder()
                .isShowForm(1)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(1)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(orderNum)
                .build();
        ValidateVo validateVo=ValidateVo.builder()
                .fieldHref("")
                .dictField("")
                .dictTable("")
                .dictText("")
                .build();
        ForeignKeyVo foreignKeyVo=ForeignKeyVo.builder()
                .build();
        IndexVo indexVo=IndexVo.builder()
                .build();
        SearchVo searchVo=SearchVo.builder()
                .build();

        ColumnVoDomain columnTypeName = ColumnVoDomain.builder()
                .dbVo(dbVo)
                .pageVo(pageVo)
                .validateVo(validateVo)
                .foreignKeyVo(foreignKeyVo)
                .indexVo(indexVo)
                .searchVo(searchVo)
                .build();
        singletree.getColumnVoDomainList().add(columnTypeName);
    }

    private static void setupImage(TableVoDomain singletree, int orderNum) {
        //设置dbimage
        DbVo dbVo=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("pic")
                .dbFieldTxt("分类图片")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .build();
        PageVo pageVo=PageVo.builder()
                .isShowForm(1)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(1)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("image")
                .orderNum(orderNum)
                .build();
        ValidateVo validateVo=ValidateVo.builder()
                .fieldHref("")
                .dictField("")
                .dictTable("")
                .dictText("")
                .build();
        ForeignKeyVo foreignKeyVo=ForeignKeyVo.builder()
                .build();
        IndexVo indexVo=IndexVo.builder()
                .build();
        SearchVo searchVo=SearchVo.builder()
                .build();

        ColumnVoDomain columnTypeName = ColumnVoDomain.builder()
                .dbVo(dbVo)
                .pageVo(pageVo)
                .validateVo(validateVo)
                .foreignKeyVo(foreignKeyVo)
                .indexVo(indexVo)
                .searchVo(searchVo)
                .build();
        singletree.getColumnVoDomainList().add(columnTypeName);

    }
    private static void setupParent(TableVoDomain singletree, int orderNum) {
        //设置dbParent
        DbVo dbVo=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("pid")
                .dbFieldTxt("父级节点")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .build();
        PageVo pageVo=PageVo.builder()
                .isShowForm(1)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("text")
                .orderNum(orderNum)
                .build();
        ValidateVo validateVo=ValidateVo.builder()
                .fieldHref("")
                .dictField("")
                .dictTable("")
                .dictText("")
                .build();
        ForeignKeyVo foreignKeyVo=ForeignKeyVo.builder()
                .build();
        IndexVo indexVo=IndexVo.builder()
                .build();
        SearchVo searchVo=SearchVo.builder()
                .build();

        ColumnVoDomain columnVoDomain = ColumnVoDomain.builder()
                .dbVo(dbVo)
                .pageVo(pageVo)
                .validateVo(validateVo)
                .foreignKeyVo(foreignKeyVo)
                .indexVo(indexVo)
                .searchVo(searchVo)
                .build();
        singletree.getColumnVoDomainList().add(columnVoDomain);
    }
    private static void setupHasChild(TableVoDomain singletree, int orderNum) {
        //设置dbHasChild字段
        DbVo dbVo=DbVo.builder()
                .dbIsKey(0)
                .dbFieldName("has_child")
                .dbFieldTxt("是否有子节点")
                .dbType("string")
                .dbLength(120)
                .dbIsNull(1)
                .build();
        PageVo pageVo=PageVo.builder()
                .isShowForm(0)
                .isReadOnly(0)
                .isQuery(0)
                .isShowList(0)
                .queryMode("single")
                .sortFlag("N")
                .fieldShowType("list")
                .orderNum(orderNum)
                .build();
        ValidateVo validateVo=ValidateVo.builder()
                .fieldHref("")
                .dictField("yn")
                .dictTable("")
                .dictText("")
                .build();
        ForeignKeyVo foreignKeyVo=ForeignKeyVo.builder()
                .build();
        IndexVo indexVo=IndexVo.builder()
                .build();
        SearchVo searchVo=SearchVo.builder()
                .build();

        ColumnVoDomain columnVoDomain = ColumnVoDomain.builder()
                .dbVo(dbVo)
                .pageVo(pageVo)
                .validateVo(validateVo)
                .foreignKeyVo(foreignKeyVo)
                .indexVo(indexVo)
                .searchVo(searchVo)
                .build();
        singletree.getColumnVoDomainList().add(columnVoDomain);
    }
}
